<?php
    include APPLICATION_PATH . '/application/views/head.phtml';
    include APPLICATION_PATH . '/application/views/top.phtml';
    include APPLICATION_PATH . '/application/views/left.phtml';
//print_r($RobotsList);
?>
<script src="/public/js/jquery-migrate-1.2.1.min.js" type="text/javascript"></script>
<script >


$(document).ready(function() {
	 
	var __ArtiForm = $('#form_user_add');
	var __editForm = $('#form_user_edit');
	$('#submit_form').click(function() {

		var objArtiForm = {
			__formName: $("select[name='add_coll_name']", __ArtiForm),
			__formFile: $("input[name='fileName']", __ArtiForm),
			__formType: $("select[name='add_coll_type']", __ArtiForm),
			__formRobot: $("input[name='robot']", __ArtiForm),
			__formAddress: $("input[name='robot_address']", __ArtiForm),
			__formStatus: $("select[name='status']", __ArtiForm),
			__formRemark: $("textarea[name='remark']", __ArtiForm)
		}

		for (var i in objArtiForm) {

			if (objArtiForm[i].val() == '') {
				objArtiForm[i].css({
					'border-color': 'red'
				});
				return false;
			} else {
				objArtiForm[i].css({
					'border-color': '#e5e5e5'
				});
			}

		}
		$.ajax({
			type: "POST",
			url: "/Robots/add",
			data: {
				"name": objArtiForm.__formName.val(),
				"fileName": objArtiForm.__formFile.val(),
				"type": objArtiForm.__formType.val(),
				"robot": objArtiForm.__formRobot.val(),
				"address": objArtiForm.__formAddress.val(),
				"status": objArtiForm.__formStatus.val(),
				"remark": objArtiForm.__formRemark.val(),
				"docu_file":$('#add_coll_type option:selected').data('remark')
			},
			success: function(data) {
				layer.alert(data.info, function() {
					if (true === data.status) window.location = "/Robots/list";
				});
			}
		});

	});
	//$('.tableDelete').click(function(){
	$(document).on('click', '.tableDelete', function() {
		var userId = $(this).parent('td').attr('item_id'),
			thisUrl = $(this).attr('href');
			//alert(thisUrl);
		//官网欢迎页   
		layer.confirm('确认删除', {
			btn: ['确认', '取消'] //按钮
		}, function(index) {

			$.ajax({
				type: "GET",
				url: thisUrl,
				async: true,
				data: {
					//"id" : userId
				},
				success: function(data) {
					layer.alert(data.info, function() {
						if (true === data.status) window.location = "/Robots/list";
					});
				}
			});
			layer.close(index);
			return false;

		}, function(index) {
			layer.close(index);
		});
		return false;

	});

	//$('.tableEdit').click(function(){
	$(document).on('click', '.tableEdit', function(e) {
		var urlOld = $(this).attr('href'),
			urlArr = urlOld.split("/");
		urlId = urlArr[urlArr.length - 1];
		$('#modal_edit').modal('toggle');
		$(this).attr({
			'href': '#form_modal_edit',
			'data-toggle': 'modal',
			'data-target': '#form_modal_edit'
		});
		current_status = $(this).parent('td').attr('status');
		current_website = $(this).parent('td').attr('website');
		current_typical = $(this).parent('td').attr('article_type');


		objEditForm = {
			_name: $("select[name='update_coll_name']", __editForm),
			_type: $("select[name='update_coll_type']", __editForm),
			_file: $("input[name='fileName']", __editForm),
			_robot: $("input[name='robot']", __editForm),
			_address: $("input[name='update_address']", __editForm),
			_status: $("select[name='status']", __editForm),
			_remark: $("textarea[name='remark']", __editForm)
		};
		var __parent = $(this).parent('td').parent('tr.gradeX'),
			_name = $("select[name='update_coll_name']", __editForm),
			_type = $("select[name='update_coll_type']", __editForm),
			_file = $("input[name='fileName']", __editForm),
			_robot = $("input[name='robot']", __editForm),
			_address = $("input[name='update_address']", __editForm),
			_status = $("select[name='status']", __editForm),
			_remark = $("textarea[name='remark']", __editForm);

		var tdTable = [];
		$('td', __parent).each(function() {
			tdTable.push($(this).text());
		});
//alert(tdTable);
		_name.val(current_website);
		_type.val(current_typical);
		_file.val(tdTable[2]);
		_robot.val(tdTable[4]);
		_address.val(tdTable[5])
		_status.val(current_status);
		_remark.val(tdTable[7]);

		return false;
	});
//alert(objEditForm._website.val());
	$('#submitEdit').click(function() {
		
		for (var i in objEditForm) {
			if ( objEditForm[i].val() == ''  ) {
				objEditForm[i].css({
					'border-color': 'red'
				});
				return false;
			} else {
				objEditForm[i].css({
					'border-color': '#e5e5e5'
				});
			}
			//alert(objEditForm[i].val());
		}
		$.ajax({
			type: "POST",
			url: "/Robots/edit/id/" + urlId,
			async: true,
			data: {
				"name": objEditForm._name.val(),
				"article_type_id" : objEditForm._type.val(),
				"robot": 　objEditForm._robot.val(),
				"file": 　objEditForm._file.val(),
				"address": objEditForm._address.val(),
				"status": objEditForm._status.val(),
				"remark": objEditForm._remark.val()
			},
			success: function(data) {
				layer.alert(data.info, function() {
					if (true === data.status) window.location = "/Robots/list";
				});
			}
		});


	});

	$(document).on('click', '#page_next,#page_prev,#page_index,#page_end', function() {
		var urlOld = $(this).attr('href'),
			urlArr = urlOld.split("/");
		urlId = urlArr[urlArr.length - 1];
		$.ajax({
			type: 'POST',
			url: '/Robots/page/page/' + urlId,
			data: urlId,
			success: function(data) {
				var data = $.parseJSON(data);

				$('#tbody').html('');
				var id = '';

				$.each(data, function(k, v) {
					//console.log('k='+k);
					id = v['robot_id'];
					$('#tbody').append($('<tr class="gradeX"><td style="display:none;">' + v['website_id'] + '</td><td>' + v['website_name'] + '</td><td>' + v['name'] + '</td><td>' + v['article_name'] + '</td><td>' + v['robot'] + '</td><td>' + v['chanel_website'] + '</td><td>' + v['robots_status'] + '</td><td>' + v['remark'] + '</td><td>' + v['current_time'] + '</td><td status="' + v['status'] + '" website="' + v['website_id'] + '" cate_id="' + id + '" item_id="' + id + '" article_type="' + v['article_type_id'] + '"><a class="tableDelete" href="/Robots/del/id/' + id + '">删除</a> / <a class="tableEdit" href="/Robots/edit/id/' + id + '">修改</a> </td></tr>'));


				});

			}

		});
		$.ajax({
			type: 'POST',
			url: '/Robots/currentPage/page/' + urlId,
			data: urlId,
			success: function(data) {
				//console.log(data);
				$('#pages').html(data);
				$('#pages').ready(function() {
					nextBtn = $('#page_next');
				});
			}

		});
		return false;
	});

});
</script>

<div id="thispage" data-id="41"></div>
		<!-- BEGIN PAGE -->

		<div class="page-content">

			<!-- BEGIN SAMPLE PORTLET CONFIGURATION MODAL FORM-->

			<div id="portlet-config" class="modal hide">

				<div class="modal-header">

					<button data-dismiss="modal" class="close" type="button"></button>

					<h3>portlet Settings</h3>

				</div>

				<div class="modal-body">

					<p>Here will be a configuration form</p>

				</div>

			</div>

			<!-- END SAMPLE PORTLET CONFIGURATION MODAL FORM-->

			<!-- BEGIN PAGE CONTAINER-->        

			<div class="container-fluid">

				<!-- BEGIN PAGE HEADER-->

				<div class="row-fluid">

					<div class="span12">

						<!-- BEGIN STYLE CUSTOMIZER -->

						<div class="color-panel hidden-phone">

							<!-- <div class="color-mode-icons icon-color"></div> -->

							<div class="color-mode-icons icon-color-close"></div>

							<div class="color-mode">

								<p>THEME COLOR</p>

								<ul class="inline">

									<li class="color-black current color-default" data-style="default"></li>

									<li class="color-blue" data-style="blue"></li>

									<li class="color-brown" data-style="brown"></li>

									<li class="color-purple" data-style="purple"></li>

									<li class="color-grey" data-style="grey"></li>

									<li class="color-white color-light" data-style="light"></li>

								</ul>

								<label>

									<span>Layout</span>

									<select class="layout-option m-wrap small">

										<option value="fluid" selected>Fluid</option>

										<option value="boxed">Boxed</option>

									</select>

								</label>

								<label>

									<span>Header</span>

									<select class="header-option m-wrap small">

										<option value="fixed" selected>Fixed</option>

										<option value="default">Default</option>

									</select>

								</label>

								<label>

									<span>Sidebar</span>

									<select class="sidebar-option m-wrap small">

										<option value="fixed">Fixed</option>

										<option value="default" selected>Default</option>

									</select>

								</label>

								<label>

									<span>Footer</span>

									<select class="footer-option m-wrap small">

										<option value="fixed">Fixed</option>

										<option value="default" selected>Default</option>

									</select>

								</label>

							</div>

						</div>

						<!-- END BEGIN STYLE CUSTOMIZER -->  

						<!-- BEGIN PAGE TITLE & BREADCRUMB-->

						<h3 class="page-title">

							机器人列表

						</h3>

						<ul class="breadcrumb">

							<li>

								<i class="icon-home"></i>
								<span>当前位置：</span>
								<span>首页</span>
								<i class="icon-angle-right"></i>

							</li>

							<li>

								<span>采集管理</span>

								<i class="icon-angle-right"></i>

							</li>

							<li><span>机器人列表</span></li>

						</ul>

						<!-- END PAGE TITLE & BREADCRUMB-->

					</div>

				</div>

				<!-- END PAGE HEADER-->

				<!-- BEGIN PAGE CONTENT-->

				<div class="row-fluid">

					<div class="span6 responsive" data-tablet="span12 fix-offset" data-desktop="span6" style="width:100%;">

						<!-- BEGIN EXAMPLE TABLE PORTLET-->

						<div class="portlet box grey">

							<div class="portlet-title">

								<div class="caption"><i class="icon-user"></i>机器人列表</div>

								<div class="actions controls">

									<a href="#modal_add" data-toggle="modal" data-target="#modal_add" class="btn blue"><i class="icon-pencil"></i> 添加</a>
									<!--<a href="/Index/Authority/add" class="btn blue"><i class="icon-pencil"></i> 添加</a>-->

								</div>

							</div>

							<div class="portlet-body">

								<table class="table table-striped table-bordered table-hover" id="current_table">

									<thead>

										<tr>
											<!--<th style="width:8px;"><input type="checkbox" class="group-checkable" data-set="#sample_2 .checkboxes" /></th>-->
											<th>采集网站</th>
											<th>文件名称</th>
											<th>文章类型</th>
											<th>机器人</th>
											<th>采集网址</th>
											<th>状态</th>
											<th>描述</th>
											<th>创建时间</th>
											<th>操作</th>
										</tr>
									</thead>

									<tbody id="tbody">
<?php
    foreach ($robots_list as $k => $v) {
        $status = empty($v['status']) ? '无效' : '正常';
        $style = (0 == ($k % 2)) ? 'odd' : 'even';
        echo <<< EOF
										<tr class="{$style} gradeX">
											<td style="display:none;">{$v['website_id']}</td>
											<td>{$v['website_name']}</td>
											<td>{$v['name']}</td>
											<td>{$v['article_name']}</td>
											<td>{$v['robot']}</td>
											<td>{$v['chanel_website']}</td>
											<td>{$status}</td>
											<td>{$v['remark']}</td>
											<td>{$v['current_time']}</td>
											<td item_id="{$v['robot_id']}" website="{$v['website_id']}" status="{$v['status']}" article_type="{$v['article_type_id']}" ><a class="tableDelete" href="/Robots/del/id/{$v['robot_id']}">删除</a> / <a class="tableEdit" href="/Robots/edit/id/{$v['robot_id']}">修改</a></td>
										</tr>
EOF;
    }
?>
									</tbody>
                </table>
<div id="pages">
<?php
    if($robots_list[0]['rows']/$robots_list[0]['every_page']<=1)
        {
            
        }
        else
        {
            print_r($allpage);
        }
?>
</div>

							</div>

						</div>
                        <div id="modal_add" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel3" aria-hidden="true">

									<div class="modal-header">

										<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>

										<h3 id="myModalLabel3">添加机器人</h3>

									</div>

									<div class="modal-body">

										<form action="#" id="form_user_add" method="post" class="form-horizontal">

											<div class="control-group">

												<label class="control-label">采集网站</label>

												<div class="controls">

													<!-- <input type="text" class="colorpicker-default m-wrap" name="name" value=""> -->
													<select id="add_coll_name" name="add_coll_name">
<?php
 foreach ($address_list AS $k => $v) {
        echo '<option value="' . $v['website_id'] . '">' . $v['web'] . '</option>';
    }
														
?>
                                						
                            						</select>

												</div>

											</div>

											<div class="control-group">

												<label class="control-label">文章类型</label>

												<div class="controls">

													<!-- <input type="text" class="colorpicker-default m-wrap" name="name" value=""> -->
													<select id="add_coll_type" name="add_coll_type">
<?php
 foreach ($typicle_list AS $k => $v) {
        echo '<option value="' . $v['article_type_id'] . '" data-remark="' . $v['remark'] . '">' . $v['name'] . '</option>';
    }
														
?>
                                						
                            						</select>

												</div>

											</div>



											<div class="control-group">

												<label class="control-label">机器人</label>

												<div class="controls">

													<input type="text" class="colorpicker-default m-wrap" name="robot" value="">

												</div>

											</div>
											<div class="control-group">

												<label class="control-label">文件名称</label>

												<div class="controls">

													<input type="text" class="colorpicker-default m-wrap" name="fileName" value="">
												</div>

											</div>

											<div class="control-group">

												<label class="control-label">采集网址</label>

												<div class="controls">

													<input type="text" class="colorpicker-default m-wrap" name="robot_address" value="" id="urls" onchange="CheckUrl()">

												</div>
												<script type="text/javascript">
                                                    $(document).ready(function(){
      var txtUrl= $("#urls").val();
        
      $("#urls").on("blur",function(){
        var txtUrl= $("#urls").val();
        var reg =  /^((https|http|ftp|rtsp|mms)?:\/\/)[^\s]+/;
          if(!reg.test(txtUrl)){
            layer.alert("请输入正确URL");
            return false;
          }/*else{
            alert("ok");
            return true;*/
         
        });
        
      });

                                                </script>

											</div>
											
                                            <div class="control-group">

                                                <label class="control-label">状态</label>
        										
                                                <div class="controls">
                                                
                                                   <select id="status" name="status">
                                						<option value="1">正常</option>
                                						<option value="0">无效</option>
                            						</select>
                                            
												</div>
        
                                            </div>
                                            
                                            
											<div class="control-group">

												<label class="control-label">描述</label>

												<div class="controls">

													<textarea class="colorpicker-default m-wrap" name="remark"></textarea>

												</div>

											</div>
                                            
											

										</form>

									</div>

									<div class="modal-footer">

										<button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>

										<button class="btn green btn-primary" id="submit_form" data-dismiss="modal" >提交</button>
                                        
									</div>

								</div>

								<div id="modal_edit" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel3" aria-hidden="true">

									<div class="modal-header">

										<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>

										<h3 id="myModalLabel3">修改机器人信息</h3>

									</div>

									<div class="modal-body">

										<form action="#" id="form_user_edit" method="post" class="form-horizontal">
											
											<div class="control-group">

												<label class="control-label">采集网站</label>

												<div class="controls">

													<select id="update_coll_name" name="update_coll_name">
<?php
 foreach ($address_list AS $k => $v) {
        echo '<option value="' . $v['website_id'] . '">' . $v['web'] . '</option>';
    }
														
?>
                                						
                            						</select>

												</div>

											</div>

											<div class="control-group">

												<label class="control-label">文章类型</label>

												<div class="controls">

													<!-- <input type="text" class="colorpicker-default m-wrap" name="name" value=""> -->
													<select id="update_coll_type" name="update_coll_type">
<?php
 foreach ($typicle_list AS $k => $v) {
        echo '<option value="' . $v['article_type_id'] . '">' . $v['name'] . '</option>';
    }
														
?>
                                						
                            						</select>

												</div>

											</div>

											<div class="control-group">

												<label class="control-label">机器人</label>

												<div class="controls">

													<input type="text" class="colorpicker-default m-wrap" name="robot" value="">

												</div>

											</div>

											<div class="control-group">

												<label class="control-label">文件名称</label>

												<div class="controls">

													<input type="text" class="colorpicker-default m-wrap" name="fileName" value="">
												</div>

											</div>
											<div class="control-group">

												<label class="control-label">采集网址</label>

												<div class="controls">

													<input type="text" class="colorpicker-default m-wrap" name="update_address" value="" id="update_address" onchange="CheckUrl(this)">

												</div>
												<script type="text/javascript">
                                                    $(document).ready(function(){
      var txtUrl= $("#update_address").val();
        
      $("#update_address").on("blur",function(){
        var txtUrl= $("#update_address").val();
        var reg =  /^((https|http|ftp|rtsp|mms)?:\/\/)[^\s]+/;
          if(!reg.test(txtUrl)){
            layer.alert("请输入正确URL");
            return false;
          }/*else{
            alert("ok");
            return true;*/
         
        });
        
      });
                                                </script>

											</div>
											                                            
                                            <div class="control-group">

                                                <label class="control-label">状态</label>
        										
                                                <div class="controls">
                                                
                                                    <!--<select id="groupEdit" name="group">
        
   
                                                    </select>-->
                                                    <!-- <input type="text" class="colorpicker-default m-wrap" name="status" value=""> -->

                                                    <select id="status" name="status">
                                						<option value="1">正常</option>
                                						<option value="0">无效</option>
                            						</select>
                                            
												</div>
        
                                            </div>
                                            
											<div class="control-group">

												<label class="control-label">描述</label>

												<div class="controls">

													<textarea class="colorpicker-default m-wrap" name="remark"></textarea>

												</div>

											</div>
                                            
											
                                            
											

										</form>

									</div>

									<div class="modal-footer">

										<button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>

										<button class="btn green btn-primary" id="submitEdit" data-dismiss="modal" >提交</button>
                                        
									</div>

								</div>

						<!-- END EXAMPLE TABLE PORTLET-->

					</div>

				</div>

				<!-- END PAGE CONTENT-->

			</div>

			<!-- END PAGE CONTAINER-->

		</div>

    <!-- END PAGE -->
<?php
    include APPLICATION_PATH . '/application/views/foot.phtml';
?>
